#ifdef unix
#include "AccurateTimer.h"
#include "sys/time.h"

AccurateTimer::AccurateTimer(void)
{
	last = new timeval();
	cur = new timeval();
	gettimeofday(last, 0);
}

AccurateTimer::~AccurateTimer(void)
{
	delete last;
	delete cur;
}


double AccurateTimer::reset()
{
	double time = poll();
	*last = *cur;
	return time;
}

double AccurateTimer::poll()
{
	gettimeofday(cur, 0);
	
	double diff = cur->tv_sec-last->tv_sec + (cur->tv_usec - last->tv_usec)/1000000.0;
	return diff;
}

#endif /* unix */
